'''
Created on 2017-6-20

@author: 24253
'''
import requests
import json
from db.write import add_sql


url="https://s.taobao.com/search?data-key=s&data-value=88&ajax=true&_ksTS=1497949320246_1376&q=%E5%B0%8F%E7%B1%B36&imgfile=&js=1&stats_click=search_radio_all:1&initiative_id=staobaoz_20170620&ie=utf8&app=detailproduct&through=1&bcoffset=4&p4ppushleft=6,48"
urlb="https://s.taobao.com/search?data-key=s&data-value=44&ajax=true&_ksTS=1497949320246_1376&q=%E5%B0%8F%E7%B1%B36&imgfile=&js=1&stats_click=search_radio_all:1&initiative_id=staobaoz_20170620&ie=utf8&app=detailproduct&through=1&bcoffset=4&p4ppushleft=6,48"




response = requests.get(url)   #调用urllib2向服务器发送get请求
res=response.content.decode()

data_dict=json.loads(res)
# print(data_dict)

item_list = data_dict['mods']['itemlist']['data']['auctions']
print(item_list)
result_list=[]
result={}
for item in item_list:
    result["标题"]=item['title'].replace('<span class=H>', '').replace('</span>', '')
    result["详细页面网址"]=item["detail_url"]
    result["位置"]=item["item_loc"]
    result["购买数量"]=item["view_sales"]
    result["价格"]=item["view_price"]
    
    print(result)
    result_list.append(result)
    add_sql( result_list)